package lxs.swift.verify;

public class Selects {
    /**
     * 选择第一个非空的对象
     */
    @SafeVarargs
    public static <T> T firstNonNull(T... items) throws NullPointerException {
        for (T item : items) {
            if (item != null) {
                return item;
            }
        }
        throw new NullPointerException("All items are null");
    }

    /**
     * 选择第一个非默认值的对象
     */
    @SafeVarargs
    public static <T> T firstNonEmpty(T... items) throws NullPointerException {
        for (T item : items) {
            if (Verifies.isNotEmpty(item)) {
                return item;
            }
        }
        throw new NullPointerException("All items are empty");
    }
}
